
<!-- 车型对应透视表 -->
<template>
    <div>
 <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="4" :collapse="collapse" labelWidth="110" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :is-select-column="false"
      :onRowSelectChange="selectChange"
      >
     
        <template slot="controls" slot-scope="props">
        <multiuse-button type="primary" :click="exportFileBtn.bind()">导出</multiuse-button>
      </template>
      </FilterTable>
      <BaseDialog :visible.sync="selectDelearFlag" :title="'经销商选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
        <DealerList @close="Delearclose" @save="Delearsave"></DealerList>
      </BaseDialog>
      </div>
</template>

<script>
import moment from "moment";
import DealerList from '@/pages/claimDemage/tools/DealerList.vue';
import {getListByPage, getListForExport,exporturl} from '@/api/claim/factory/ModelsCorresponding';
import { exportExcelFile } from '@/utils/index';
    export  default{
        components: {
        DealerList
        },
        data(){
            return{
                topFilterInit: this.topFilterInitFun(),
                fetchParams: {xhrAbort: true},    
                selectDelearFlag: false,
                collapse: true,
                columns: this.creatHeader(),
                fetchapi:getListByPage
            };

        },

    methods:{
    //选中
    selectChange(rows) {
    //   this.selectedRows = rows;
    //   this.disableds = this.selectedRows.length <= 0;
    //   console.log(this.selectedRows);
    },
    // 导出
  async  exportFileBtn() {
      let json = Object.assign({}, { CODE: 'CODE_00000248' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // getListForExport(this.fetchParams).then(res => {
      //   exportExcelFile(res.data, '车型对应透视表');
      // });
    },
    SelectDelear() {
      this.selectDelearFlag = true;
    },//关闭
    Delearclose() {
      this.selectDelearFlag = false;
    },
    //保存
    Delearsave(obj) {
      this.topFilterInit.map(x => {
        if ('ownerCode' == x.fieldName) {
          x.initialValue = obj[0].dealerCode; //维修工单号返显
        }
      })
      this.selectDelearFlag = false;

    },
    //搜索获取数据
    changeHandle(val) {
      /*刷新表格 用它*/
      this.fetchParams = Object.assign({}, this.fetchParams, val,{xhrAbort:false});
      console.log(this.fetchParams);
    },
    //搜索数据
    topFilterInitFun() {
      return [
         {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelCode',
          placeholder: '',
          initialValue: '',
        },
        { type: 'RANGE_DATE', label: '结算日期', fieldName: 'beginSettleAt|endSettleAt', placeholder: '请输入', initialValue: '',   initialValue: [
            moment()
              .startOf('week')
              .format('YYYY-MM-DD HH:mm:ss'),
            moment()
              .endOf('week')
              .format('YYYY-MM-DD HH:mm:ss')
          ],
          rules: [{ required: true, message: '请选择日期', trigger: 'change' }]   },
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        { title: '工厂', dataIndex: 'factName', sorter: true,hidden:true },
        {title: '车型',dataIndex: 'modelCode',sorter: true},
        { title: '索赔类型', dataIndex: 'xj', sorter: true },
        {
          title: '售后索赔金额',
          align: 'center',
          children: [
        {title: '1月',dataIndex: 'col1',sorter: true},
        {title: '2月',dataIndex: 'col2',sorter: true},
        {title: '3月',dataIndex: 'col3',sorter: true},
        {title: '4月',dataIndex: 'col4',sorter: true},
        {title: '5月',dataIndex: 'col5',sorter: true},
        {title: '6月',dataIndex: 'col6',sorter: true},
        {title: '7月',dataIndex: 'col7',sorter: true},
        {title: '8月',dataIndex: 'col8',sorter: true},
        {title: '9月',dataIndex: 'col9',sorter: true},
        {title: '10月',dataIndex: 'col10',sorter: true},
        {title: '11月',dataIndex: 'col11',sorter: true},
        {title: '12月',dataIndex: 'col12',sorter: true},
          ]
        },
        
      ];
    },
        }
    };
 </script>
<style lang="less" scoped></style>   
